package com.shyroke.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.shyroke.calculation.ExpertWeightCal;

import entity.Expert;

@Controller
@RequestMapping(value="expertAction")
public class ExpertAction {

	/**
	 * 存放所有专家的中智集
	 * key为专家艾的id  value为专家的中智集
	 */
	public static Map<Integer,Expert> expertMap=new HashMap<>();
	
	/**
	 * 保存专家输入的中智集
	 * @param expert
	 * @param model
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(value="/saveEnterInfo")
	public ModelAndView saveEnterInfo(Expert expert,ModelAndView model) throws IOException {

		if(expertMap.containsKey(expert.getId())) {
			//说明已经有该专家当中智集
		}else {
			expertMap.put(expert.getId(), expert);
			for(int i=0;i<expertMap.size();i++) {
				
			}
		}
		
		System.out.println(expertMap);
		String viewName="expert"+(expert.getId()+1);
		if(expert.getId()==4) {
			//说明是最后一个，将中智集转为矩阵输出
			List<Expert> expertList = new ArrayList<>();
			Expert expert2 = null;
			for(int i=0;i<expertMap.size();i++) {
				expert2 = expertMap.get(i+1);
				expert2.setId(i+1);
				expertList.add(expert2);
			}
			model.addObject("expertList", expertList);
		
		
			model.setViewName("show_expert");
		}else {
			model.setViewName(viewName);
		}
		
		return model;
		
	}
	

}
